//
//  HXGISViewController.m
//  KD
//
//  Created by ifly on 16/3/24.
//  Copyright © 2016年 Whx. All rights reserved.
//

#import "HXGISViewController.h"
#import "HXMessageDetailsTableViewController.h"
#import "HXPinModel.h"
#import "HXGISSearchView.h"
#import "HXGISRightBarView.h"
#import "HXDropdownMenu.h"

#import "HXTQJRXMViewController.h"
#import "HXChangeTQJRXMViewController.h"
#import "HXNearbyGISModel.h"

@interface HXGISViewController ()<BMKMapViewDelegate,BMKLocationServiceDelegate,HXGISSearchViewDelegate,HXGISRightBarViewDelegate,BMKGeoCodeSearchDelegate>{

    NSInteger annotationInteger;
}
@property (weak, nonatomic) IBOutlet BMKMapView *baiduMapView;
//@property(nonatomic,strong) id <BMKAnnotation> selectAnno;//最后点击的大头针模型数据 用于返回给工地质量界面
@property(nonatomic,assign) BMKCoordinateSpan span;
@property(nonatomic,strong) BMKLocationService *location;
@property(nonatomic,assign) CLLocationCoordinate2D userLocation;
@property(nonatomic,strong) NSMutableArray<HXNearbyGISListModel *> *pinModelArray;//存放现在显示在地图上的所有大头针数据模型
@property(nonatomic,strong) NSMutableArray *pinViewArray;//存放现在显示在地图上的所有大头针
@property (strong, nonatomic) UIView *maskView;//背景View
@property (strong, nonatomic) HXGISSearchView *searchAreaView;//搜索View
@property (strong, nonatomic) UIView *selectView;//地区View
@property(nonatomic,weak) HXDropdownMenu *menu;
/**所有地区代码*/
@property(nonatomic,strong) NSArray<HXAreaCodeListGISModel *> *areaCodeListGISModelArray;
///**最新获取的大头针数组*/
//@property(nonatomic,strong) NSArray<HXNearbyGISListModel *> *proListGISModelArray;
@property(nonatomic,assign) BOOL isLocationError;//是否定位失败
@property(nonatomic,assign) BOOL isYetLocation;//是否定位过 或者 是否第一次进来
//@property (nonatomic,assign) BOOL ifFirstLoad;//是否是第一次进来

#pragma mark ----- // 6.27号 \\ ------
/**记录上一次长按时的坐标*/
@property (nonatomic,assign) CGPoint lastLongCenter;

/**长按时的大头针item*/
@property (nonatomic,strong) BMKPointAnnotation * longPointAnnotationItem;

@end

@implementation HXGISViewController

-(void)dealloc{

    self.baiduMapView              = nil;
    self.location                  = nil;
    self.pinModelArray             = nil;
    self.longPointAnnotationItem   = nil;
    self.areaCodeListGISModelArray = nil;
    self.menu                      = nil;
    self.pinViewArray              = nil;
    self.maskView                  = nil;
    self.searchAreaView            = nil;
    self.selectView                = nil;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self location];//启动定位
    
    annotationInteger = 0;
    
    self.isLocationError = NO;
    self.isYetLocation = NO;
    self.baiduMapView.delegate = self;
    self.baiduMapView.showsUserLocation = YES;//显示定位图层
//    if (self.type == GISTypeNameType) {//获取工地信息
//
//    }else{
        //        [self getNearbyGISData];
        self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithImage:@"map_icon_zoom_in" highImage:@"map_icon_zoom_in_high" target:self action:@selector(rightBtnAction:)];
//    }
    
    //长按手势
    UILongPressGestureRecognizer * longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
    [self.baiduMapView addGestureRecognizer:longPress];
}

-(void)longPress:(UILongPressGestureRecognizer *)longPress {
    
    CGPoint center = [longPress locationInView:_baiduMapView];
    
    if (_lastLongCenter.x == center.x && _lastLongCenter.y == center.y) {
        
        //NSLog(@"已经添加");
        
        return;
    }
    
    CLLocationCoordinate2D coordinate = [self.baiduMapView convertPoint:center toCoordinateFromView:self.baiduMapView];
    
    
    //发起反地理编码
    BMKReverseGeoCodeOption * geoCodeOption = [[BMKReverseGeoCodeOption alloc] init];
    geoCodeOption.reverseGeoPoint = coordinate;
    
    BMKGeoCodeSearch *searcher =[[BMKGeoCodeSearch alloc]init];
    searcher.delegate = self;
    BOOL flag = [searcher reverseGeoCode:geoCodeOption];

    if (flag) {
        
        //NSLog(@"反geo检索发送成功");
        
//        _longPointAnnotationItem = [[BMKPointAnnotation alloc]init];
//        
//#pragma mark -------- // 6.27号 \\ -----------
//        _longPointAnnotationItem.coordinate = coordinate;
//        [self.longPointDataArray addObject:_longPointAnnotationItem];
//        [self.baiduMapView addAnnotation:_longPointAnnotationItem];
//        
//        _lastLongCenter = center;

    }else
    {
        NSLog(@"反geo检索发送失败");
        [SVProgressHUD showErrorWithStatus:@"网络错误"];
        
        return;
    }
}

/**
 *返回反地理编码搜索结果
 *@param searcher 搜索对象
 *@param result 搜索结果
 *@param error 错误号，@see BMKSearchErrorCode
 */
- (void)onGetReverseGeoCodeResult:(BMKGeoCodeSearch *)searcher result:(BMKReverseGeoCodeResult *)result errorCode:(BMKSearchErrorCode)error{

    if (error == BMK_SEARCH_NO_ERROR) {
        //在此处理正常结果
        NSLog(@"定位现在的地址%@",result.address);
        _longPointAnnotationItem.title = [NSString stringWithFormat:@"%@",result.address];
        
        UIAlertController * altertController = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"是否在 %@ 增加提前介入项目",result.address] message:nil preferredStyle:UIAlertControllerStyleAlert];
        
        [self presentViewController:altertController animated:YES completion:^{
            
        }];
        
        [altertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            
        }]];
        
        [altertController addAction:[UIAlertAction actionWithTitle:@"添加" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
            HXTQJRXMViewController * tqjrxmVc = [[HXTQJRXMViewController alloc] init];
            
            tqjrxmVc.addressStr = result.address;
            tqjrxmVc.coordinate = result.location;
            
            [self.navigationController pushViewController:tqjrxmVc animated:YES];
            
        }]];
        
    }
    else {
        //[SVProgressHUD showErrorWithStatus:@"网络错误"];
        //NSLog(@"抱歉，未找到结果");
    }
}

//-(void)xxxx{
//    [self.baiduMapView removeAnnotations:self.pinViewArray];
//    [self.pinViewArray removeAllObjects];
//    [self.pinModelArray removeAllObjects];
//    [self getAllGISData];
//}
- (IBAction)locationBtnClick:(id)sender {
    if (self.isLocationError) {//定位失败
        UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"" message:@"定位失败" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [alert show];
    }else{
        BMKCoordinateSpan span = BMKCoordinateSpanMake(0.10093,0.11279);
        BMKCoordinateRegion region = BMKCoordinateRegionMake(self.userLocation, span);
        [self.baiduMapView setRegion:region animated:YES];
    }
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.parentViewController.tabBarController.tabBar.hidden = YES;
    
    if (self.isYetLocation) {
        
        if (self.type == GISTypeNameType){
            [self btnClick:2];
        }else{
            [self btnClick:2];
        }
    }
}

-(void)rightBtnAction:(UIBarButtonItem *)btn{
    [self hiddenSearchAreaView];
    [self hiddenSelectView];
    HXGISRightBarView *myview = [[[NSBundle mainBundle] loadNibNamed:@"HXGISRightBarView" owner:nil options:nil] lastObject];
    myview.delegate = self;
    HXDropdownMenu *menu = [HXDropdownMenu menu];
    menu.content = myview;
    [menu showFrom:(UIView *)btn];
    self.menu = menu;
}

#pragma mark - HXGISRightBarViewDelegate
- (void)btnClick:(NSInteger)type{
    //移除所有大头针和数据模型
    [self.baiduMapView removeAnnotations:self.pinViewArray];
    [self.pinViewArray removeAllObjects];
    [self.pinModelArray removeAllObjects];
    if (type == 1) {//全部
        [self getAllGISData];
    }else if (type == 2){//周边
        [self getNearbyGISData];
    }else if (type == 3){//搜索
        [self showSearchAreaView];
    }else if (type == 4){//区域
        [self showSelectView];
    }else{
        
    }
    [self.menu dismiss];
}

//所有工地
-(void)getAllGISData{
    annotationInteger = 0;
    [SVProgressHUD showWithStatus:@"工地较多,请稍后......"];
    [NetworkAPI getGISWithAreaCode:@"3702"
                           success:^(HXNearbyGISModel *result) {
                               if ([result.Code isEqualToString:@"200"]) {
//                                   if (result.Msglist.count == 0) {
//                                       [SVProgressHUD showErrorWithStatus:@"暂无工地数据"];
//                                   }
                                   [self.pinModelArray removeAllObjects];
                                   [self.pinViewArray removeAllObjects];
                                   [self.pinModelArray addObjectsFromArray:result.Msglist];
                                   [self addPinWithArray:result.Msglist];
                                   [SVProgressHUD dismiss];
//                                   NSLog(@"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
                               }else{
                                   [SVProgressHUD showErrorWithStatus:@"暂无工地数据"];
                               }
        
                                } failure:^(NSError *err) {
                                    [SVProgressHUD showErrorWithStatus:@"网络错误"];
                                }];
}

//获取附近的工地
-(void)getNearbyGISData{
    annotationInteger = 0;
    if (self.isLocationError) {//定位失败
        UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"" message:@"定位失败" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
        [alert show];
        return;
    }
    [SVProgressHUD showWithStatus:@"工地较多,请稍后......"];
    NSString *x = [NSString stringWithFormat:@"%f",self.userLocation.longitude];
    NSString *y = [NSString stringWithFormat:@"%f",self.userLocation.latitude];
    [NetworkAPI getNearbyGISWithPointX:x
                                PointY:y
                               success:^(HXNearbyGISModel *result) {
                                   if ([result.Code isEqualToString:@"200"]) {
//                                       if (result.Msglist.count == 0) {
//                                           [SVProgressHUD showErrorWithStatus:@"暂无工地数据"];
//                                       }
                                       
                                       [self.pinModelArray removeAllObjects];
                                       [self.pinViewArray removeAllObjects];
                                       [self.pinModelArray addObjectsFromArray:result.Msglist];
                                       [self addPinWithArray:result.Msglist];
                                       [SVProgressHUD dismiss];
                                   }else{
                                       [SVProgressHUD showErrorWithStatus:@"获取工地错误"];
                                   }
                               } failure:^(NSError *err) {
                                   [SVProgressHUD showErrorWithStatus:@"获取工地错误"];
                                   [SVProgressHUD dismiss];
                               }];
}

//根据名称搜索工地
-(void)searchNameGISDataWithName:(NSString *)name Area:(NSString *)area{
     [SVProgressHUD showWithStatus:@"正在搜索" ];
    [NetworkAPI searchProWithName:name
                          address:area
                          success:^(HXNearbyGISModel *result) {
                              if ([result.Code isEqualToString:@"200"]) {
//                                  if (result.Msglist.count == 0) {
//                                       [SVProgressHUD showErrorWithStatus:@"暂无工地数据"];
//                                  }
                                  [self.pinModelArray removeAllObjects];
                                  [self.pinViewArray removeAllObjects];
                                  [self.pinModelArray addObjectsFromArray:result.Msglist];
                                  [self addPinWithArray:result.Msglist];
                                  [SVProgressHUD dismiss];
                              }else{
                                  [SVProgressHUD showErrorWithStatus:@"暂无工地数据"];
                              }
                          } failure:^(NSError *err) {
                              [SVProgressHUD showErrorWithStatus:@"网络错误"];
                          }];
}

-(void)getAreaCode{
    [SVProgressHUD showWithStatus:@"正在获取地区" ];
    [NetworkAPI getAreaCodeSuccess:^(HXAreaCodeGISModel *result) {
        if ([result.Code isEqualToString:@"200"]) {
            [SVProgressHUD dismiss];
             self.areaCodeListGISModelArray = result.Msglist;
            self.selectView = nil;
            [self.view addSubview:self.maskView];
            [self.view addSubview:self.selectView];
        }else{
            [SVProgressHUD showErrorWithStatus:@"暂无地区数据"];
        }
    } failure:^(NSError *err) {
         [SVProgressHUD showErrorWithStatus:@"获取地区错误"];
    }];
}
//根据地区显示项目
-(void)getAreaProWithCode:(NSString *)code{
    [SVProgressHUD showWithStatus:@"正在加载" ];
    [NetworkAPI getAreaProWithCode:code
                           success:^(HXNearbyGISModel *result) {
                               if ([result.Code isEqualToString:@"200"]) {
//                                   if (result.Msglist.count == 0) {
//                                       [SVProgressHUD showErrorWithStatus:@"暂无工地数据"];
//                                   }
                                   [self.pinModelArray removeAllObjects];
                                   [self.pinViewArray removeAllObjects];
                                   [self.pinModelArray addObjectsFromArray:result.Msglist];
                                   [self addPinWithArray:result.Msglist];
                                   [SVProgressHUD dismiss];
                               }else{
                                   [SVProgressHUD showErrorWithStatus:@"暂无工地数据"];
                               }
                           } failure:^(NSError *err) {
                               [SVProgressHUD showErrorWithStatus:@"获取工地错误"];
                           }];
}

//添加大头针
-(void)addPinWithArray:(NSArray<HXNearbyGISListModel*>*)array{
    for (HXNearbyGISListModel *model in array) {
        CLLocationCoordinate2D pt = (CLLocationCoordinate2D){[model.PointY doubleValue], [model.PointX doubleValue]};
        [self addAnnoWithPT:pt andTitle:model.PrjName andAddress:[NSString stringWithFormat:@"%@                                                                                            $%@$%@$%@$%@",model.AllState,model.PrjAddress,model.KeyGUID,model.PointX,model.PointY]];
    }
}

- (void)addAnnoWithPT:(CLLocationCoordinate2D)coor andTitle:(NSString *)title andAddress:(NSString *)address{
    BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];//BMKAnnotationView
    annotation.coordinate = coor;
    annotation.title = title;
    annotation.subtitle = address;
    [self.pinViewArray addObject:annotation];//拿到所有大头针 方便一会移除
    [self.baiduMapView addAnnotation:annotation];
}

- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation{
    if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {
        static NSString *pinID = @"PIN";
        BMKPinAnnotationView *newAnnotationView = (BMKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:pinID];
        if (newAnnotationView == nil) {
            newAnnotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pinID];
        }
        newAnnotationView.annotation = annotation;
        newAnnotationView.animatesDrop = YES;

        //安全判断
        if(self.pinModelArray.count - 1 < annotationInteger) {
            return nil;
        };

        HXNearbyGISListModel * model = self.pinModelArray[annotationInteger];
        
        if ([model.DataType intValue] == 0) {
            
            newAnnotationView.pinColor = BMKPinAnnotationColorRed;

        }else if ([model.DataType intValue] == 1){
        
            //NSLog(@"-------------- model is %@",model.PointY);
            
            newAnnotationView.pinColor = BMKPinAnnotationColorGreen;
        }
        
        UIImageView *imageView = [[UIImageView alloc]init];
        imageView.contentMode = UIViewContentModeRight;
        imageView.frame = CGRectMake(0, 0, 12, 16);
        imageView.image = [UIImage imageNamed:@"rightgo"];
        newAnnotationView.rightCalloutAccessoryView = imageView;
        
        annotationInteger ++;
        
        return newAnnotationView;
    }
    return nil;
}

//点击大头针时
/**在 中添加了属性keyGuid 用于抓取详细信息  框架更新时记得添加*/
//-(void)mapView:(BMKMapView *)mapView didSelectAnnotationView:(BMKAnnotationView *)view
//{
//    self.selectAnno = view.annotation;
//}
///Users/ifly/Desktop/KD/KD/classes/Apply/Controller/HXGISViewController.m:210:21: Assigning to 'BMKPointAnnotation *' from incompatible type 'id<BMKAnnotation>'
- (void)mapView:(BMKMapView *)mapView annotationViewForBubble:(BMKAnnotationView *)view{
    id annotation = view.annotation;
    if (self.type == GISTypeNameType) {//只获取名字和地址
        [self.delegate siteName:[annotation title] address:[annotation subtitle]];
        [self.navigationController popViewControllerAnimated:YES];
    }else{//进入下一个页面拉去更
        NSString *keyGuid = @"";
        NSString *dataType = @"";
        for (HXNearbyGISListModel *model in self.pinModelArray) {
            if ([model.PrjName isEqualToString:[annotation title]]) {
                keyGuid = model.KeyGUID;
                dataType = model.DataType;
            }
        }
        if ([keyGuid isEqualToString:@""]) {
            return;
            //NSAssert(0, @"查找key错误");
            
//            UIAlertController * altertController = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"是否在 %@ 增加提前介入项目",[annotation title]] message:nil preferredStyle:UIAlertControllerStyleAlert];
//            
//            [self presentViewController:altertController animated:YES completion:^{
//                
//            }];
//            
//            [altertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//                
//                
//            }]];
//            
//            [altertController addAction:[UIAlertAction actionWithTitle:@"添加" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//                
//                HXTQJRXMViewController * tqjrxmVc = [[HXTQJRXMViewController alloc] init];
//                
//                tqjrxmVc.addressStr = [annotation title];
//                tqjrxmVc.coordinate = [annotation coordinate];
//                
//                [self.navigationController pushViewController:tqjrxmVc animated:YES];
//                
//            }]];
//            
//            
//            return;
        }
        if ([dataType isEqualToString:@"0"]) {
            
            HXMessageDetailsTableViewController *vc = [HXMessageDetailsTableViewController initWithkeyGuid:keyGuid];
            [self.navigationController pushViewController:vc animated:YES];
        }else if ([dataType isEqualToString:@"1"]){
        
            HXChangeTQJRXMViewController * changeVc = [HXChangeTQJRXMViewController initWithKeyGuid:keyGuid];
            
            [self.navigationController pushViewController:changeVc animated:YES];
        }
    }
}

#pragma mark - BMKLocationServiceDelegate
/**获得位置时*/
- (void)didUpdateBMKUserLocation:(BMKUserLocation *)userLocation{
    [self.baiduMapView updateLocationData:userLocation];
    self.userLocation = userLocation.location.coordinate;
    
    if (self.isYetLocation) return;
    CLLocationCoordinate2D center = userLocation.location.coordinate;
    BMKCoordinateSpan span = BMKCoordinateSpanMake(0.101686, 0.114705);
    BMKCoordinateRegion region = BMKCoordinateRegionMake(center, span);
    [self.baiduMapView setRegion:region animated:YES];
    if (self.type == GISTypeNameType){
        [self btnClick:2];
    }else{
        [self btnClick:2];
    }
    self.isYetLocation = YES;
}

/**
 *定位失败后，会调用此函数
 *@param error 错误号
 */
- (void)didFailToLocateUserWithError:(NSError *)error{
    self.isLocationError = YES;
}

#pragma mark - maskView
- (UIView *)maskView{
    if (!_maskView) {
        _maskView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, HXSCREEN_WIDTH, HXSCREEN_HEIGHT)];
        _maskView.backgroundColor=[UIColor blackColor];
        _maskView.alpha=0.4;
        UIGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(maskViewClick:)];
        [_maskView addGestureRecognizer:tap];
    }
    return _maskView;
}

-(void)maskViewClick:(UIPanGestureRecognizer *)rec{
//    [UIView animateWithDuration:0.5 animations:^{
//        self.maskView.alpha=0;
//    } completion:^(BOOL finished) {
//        [self.maskView removeFromSuperview];
//    }];
    [self hiddenSelectView];
    [self hiddenSearchAreaView];
}

#pragma mark - searchView
- (HXGISSearchView *)searchAreaView{
    if (_searchAreaView == nil) {
        _searchAreaView = [[[NSBundle mainBundle]loadNibNamed:@"HXGISSearchView" owner:nil options:nil] lastObject];//270-130
        _searchAreaView.delegate = self;
        _searchAreaView.frame = CGRectMake((HXSCREEN_WIDTH - 270)/2, 180, 270, 130);
    }
    return _searchAreaView;
}

-(void)showSearchAreaView{
    annotationInteger = 0;
    [self.view addSubview:self.maskView];
    [self.view addSubview:self.searchAreaView];
}

-(void)hiddenSearchAreaView{
    [self.maskView removeFromSuperview];
    [self.searchAreaView removeFromSuperview];
}

// searchViewDelegate
- (void)searchAreaName:(NSString *)name Area:(NSString *)area{
    [self hiddenSearchAreaView];
    [self searchNameGISDataWithName:name Area:area];
}

#pragma mark - selectView
- (UIView *)selectView{
    if (_selectView == nil) {
        _selectView = [[UIView alloc]init];
        _selectView.backgroundColor = [UIColor clearColor];
        _selectView.frame = CGRectMake((HXSCREEN_WIDTH - 200)/2.0, 100, 200, 350);
        UIScrollView *scrollView = [[UIScrollView alloc]init];
        scrollView.showsVerticalScrollIndicator = NO;
        scrollView.frame = CGRectMake(0, 0, 200, 350);
        [_selectView addSubview:scrollView];
        scrollView.contentSize = CGSizeMake(200, self.areaCodeListGISModelArray.count*35);
        for (int i = 0;i<self.areaCodeListGISModelArray.count;i++) {
            HXAreaCodeListGISModel *model = self.areaCodeListGISModelArray[i];
            UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
            [btn setFrame:CGRectMake(0, i*35, 200, 30)];
            btn.tag = 1000+i;
            [btn addTarget:self action:@selector(selectProBtnClick:) forControlEvents:UIControlEventTouchUpInside];
            [btn setTitle:model.Title forState:UIControlStateNormal];
            [scrollView addSubview:btn];
            btn.backgroundColor = HXRandomColor;
        }
    }
    return _selectView;
}

-(void)showSelectView{
    annotationInteger = 0;
    if (self.areaCodeListGISModelArray.count == 0) {
        [self getAreaCode];//获取地区以及地区代码
    }else{
        [self.view addSubview:self.maskView];
        [self.view addSubview:self.selectView];
    }
}

-(void)hiddenSelectView{
    [self.maskView removeFromSuperview];
    [self.selectView removeFromSuperview];
}

-(void)selectProBtnClick:(UIButton *)btn{
    HXAreaCodeListGISModel *model = self.areaCodeListGISModelArray[btn.tag - 1000];
    [self hiddenSelectView];
    NSString *code =[model.Code stringByReplacingOccurrencesOfString:@" " withString:@""];
    [self getAreaProWithCode:code];
}

#pragma mark - 懒加载

- (NSMutableArray *)pinViewArray{
    if (_pinViewArray == nil) {
        _pinViewArray = [[NSMutableArray alloc]init];
    }
    return _pinViewArray;
}
-(BMKLocationService *)location{
    if (!_location) {
        _location = [[BMKLocationService alloc]init];
        _location.delegate = self;
        [_location startUserLocationService];
    }
    return _location;
}

- (NSMutableArray<HXNearbyGISListModel *> *)pinModelArray{
    if (_pinModelArray == nil) {
        _pinModelArray = [[NSMutableArray alloc]init];
    }
    return _pinModelArray;
}

@end
